using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.IServices.Equipments;
using System.Threading.Tasks;
using VOL.Core.Controllers.Basic;
using VOL.Core.Filters;
using VOL.Core.Utilities.Response;
using VOL.Entity.AttributeManager;
using VOL.Entity.DomainModels.Core;
using VOL.Entity.DomainModels.Equipment;

namespace VOL.WebApi.Controllers.MyMES
{
    /// <summary>
    /// 设备维修单管理控制器
    /// </summary>
    [Route("api/RepairForm")]
    [ApiController]
    [AllowAnonymous] // 允许匿名访问
    [PermissionTable(Name = "RepairForm")]
    public class RepairFormController : ApiBaseController<IRepairFormService>
    {
        private readonly IRepairFormService _repairFormService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repairFormService">维修单服务</param>
        public RepairFormController(IRepairFormService repairFormService)
            : base(repairFormService)
        {
            _repairFormService = repairFormService;
        }

        /// <summary>
        /// 获取维修单列表
        /// </summary>
        /// <param name="dto">查询参数</param>
        /// <returns>维修单列表（分页）</returns>
        [HttpPost("GetRepairForm")]
        public async Task<ActionResult> GetRepairForm([FromBody] GetRepairFormDto dto)
        {
            return Json(await _repairFormService.GetRepairForm(dto));
        }

        /// <summary>
        /// 添加维修单
        /// </summary>
        /// <param name="repairForm">维修单实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("AddRepairForm")]
        public async Task<WebResponseContent> AddRepairForm([FromBody] RepairForm repairForm)
        {
            return await _repairFormService.AddRepairForm(repairForm);
        }

        /// <summary>
        /// 更新维修单
        /// </summary>
        /// <param name="repairForm">维修单实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("UpdRepairForm")]
        public async Task<WebResponseContent> UpdRepairForm([FromBody] RepairForm repairForm)
        {
            return await _repairFormService.UpdRepairForm(repairForm);
        }

        /// <summary>
        /// 删除维修单
        /// </summary>
        /// <param name="ids">维修单ID列表，以逗号分隔的字符串</param>
        /// <returns>操作结果</returns>
        [HttpPost("DelRepairForm")]
        public async Task<WebResponseContent> DelRepairForm([FromQuery] string ids)
        {
            return await _repairFormService.DelRepairForm(ids);
        }
    }
} 